// created by noellynch
// May 14, 2011

package com.gruntdb.engines.indexedjson;

import java.nio.ByteBuffer;

import com.gruntdb.core.stubs.IGruntDBIndex;

public class IndexedJSONStorageIndex implements IGruntDBIndex {
	private		long		id;
	private		long		offset;
	private		long		size;
	private		int			fileLocationOffset;
	private		int			flags;
	
	public IndexedJSONStorageIndex(long id, long offset, long size, int fileLocationOffset,
			int flags) {
		super();
		this.id = id;
		this.offset = offset;
		this.size = size;
		this.fileLocationOffset = fileLocationOffset;
		this.flags = flags;
	}

	public IndexedJSONStorageIndex() {
		super();
	}

	/* (non-Javadoc)
	 * @see com.gruntdb.engines.indexedjson.IGruntDBIndex#getId()
	 */
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getOffset() {
		return offset;
	}

	public void setOffset(long offset) {
		this.offset = offset;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public int getFileLocationOffset() {
		return fileLocationOffset;
	}

	public void setFileLocationOffset(int fileLocationOffset) {
		this.fileLocationOffset = fileLocationOffset;
	}
	
	public int getFlags() {
		return flags;
	}

	public void setFlags(int flags) {
		this.flags = flags;
	}

	@Override
	public String toString() {
		return "GruntIndex [fileLocationOffset=" + fileLocationOffset
				+ ", flags=" + flags + ", id=" + id + ", offset=" + offset
				+ ", size=" + size + "]";
	}
	
	static	public	final	int		sizeofInBytes() {
		return 8 + 8 + 8 + 4 + 4;
	}
	
	/* (non-Javadoc)
	 * @see com.gruntdb.engines.indexedjson.IGruntDBIndex#put(java.nio.ByteBuffer)
	 */
	public	void	put(ByteBuffer cl_buffer) {
		cl_buffer.putLong(id);
		cl_buffer.putLong(offset);
		cl_buffer.putLong(size);
		cl_buffer.putInt(fileLocationOffset);
		cl_buffer.putInt(flags);
	}

	public void from(ByteBuffer clBuffer) {
		this.id = clBuffer.getLong();
		this.offset = clBuffer.getLong();
		this.size = clBuffer.getLong();
		this.fileLocationOffset = clBuffer.getInt();
		this.flags = clBuffer.getInt();
	}
	
	
	
}
